package VerifyInstalls;

import game.BetEntity;
import game.BetPosition;
import game.Player;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

public class JPAVerify 
{
	public static void main(String[] args) {
	    EntityManagerFactory entityManagerFactory =  Persistence.createEntityManagerFactory("betpersist");
	    
	    EntityManager em = entityManagerFactory.createEntityManager();
	    EntityTransaction userTransaction = em.getTransaction();
	    Player testPlayer = new Player(100);
	    
	    //Start transaction block
	    userTransaction.begin();
	      //Create the test Bet to insert into the DB -- this can be done outside the transaction
	    BetEntity testBet = new BetEntity();
	      //give it some values
	    testBet.setAmount(10);
	    testBet.setPlayerID(testPlayer.getID());
	    testBet.setPosition(BetPosition.PassLine.name());
	      //Persist the test bet
	    em.persist(testBet);
	    //Commit the transaction
	    userTransaction.commit();
	    //close the manager
	    em.close();
	    //close the factory
	    entityManagerFactory.close();
	    //output, so we know it completed
	    System.out.println("done");
	}
}
